<template>
  <j-modal title="治疗脱失告警配置" :width="600" :visible="visible" :confirmLoading="loading" switchFullscreen
    @cancel="handleCancel" @ok="handleOk">
    <p class="p1">默认脱失时间设置</p>
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol"
      style="padding:0 0 20px 20px;">
      <a-row>
        <a-col :span="24">
          <a-form-model-item label="默认脱失时间期限" prop="term">
            <a-input-number v-model="form.term" placeholder="请输入"></a-input-number>
            <span class="sp1">天</span>
            <a-tooltip placement="top" style="position: absolute;left: 3px;top: 4px;z-index: 1000;"
              :overlayStyle="{ minWidth: `300px`, maxWidth: `400px` }">
              <template slot="title">
                <div>自定义设置在规定时间内没有服药记录的，系统会触发告警</div>
              </template>
              <a-icon type="question-circle" />
            </a-tooltip>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </j-modal>
</template>
<script>
import * as treatApi from '@/api/sjsk/help/treat.js'
export default {
  components: {},
  data() {
    return {
      labelCol: { span: 7 },
      wrapperCol: { span: 8 },
      form: { term: "" },
      rules: {
        term: [{ required: true, message: '请输入' }],
      },
      loading: false,
      visible: false,
    }
  },
  created() { },
  methods: {
    show() {
      this.visible = true
      this.form.term = ""
      this.getDetail()
    },
    getDetail() {
      treatApi.getTerm().then(res => {
        if (res.success) {
          this.form.term = res.result
        } else {
          this.$message.warn(res.message)
        }
      })
        .catch(e => {
          this.$message.warn('请求失败！')
        })
    },
    handleCancel() {
      this.visible = false
    },
    handleOk() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.loading = true
          treatApi.setTerm(this.form).then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.visible = false
              this.loading = false
            } else {
              this.loading = false
              this.$message.warn(res.message)
            }
          })
            .catch(e => {
              this.loading = false
              this.$message.warn('请求失败！')
            })
        }
      })
    },
  }
}
</script>
<style scoped lang="less">
/deep/.ant-col-22 {
  text-align: left;
}

/deep/.ant-row {
  margin-bottom: 0;
}

/deep/.ant-input-number {
  margin-left: 25px;
}

.p1 {
  font-weight: bold;
}

.sp1 {
  position: absolute;
  right: -26px;
  top: -10px;
}
</style>
